package _最小生成树;

import java.util.Scanner;

/**
 * @author ShadowLim
 * @create 2022-03-19-15:52
 */
public class _通电 {
    // 静态代码块
    static class Node {
        int x, y, h;
    }
    static boolean[] vis = new boolean[1005];
    static double[][] map = new double[1005][1005];
    static double[] minSpend = new double[1005];
    static double MAX = 0x7f7f7f7f;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Node[] nodes = new Node[1005];
        for (int i = 1; i <= n; i++) {
            nodes[i] = new Node();
            nodes[i].x = scanner.nextInt();
            nodes[i].y = scanner.nextInt();
            nodes[i].h = scanner.nextInt();
        }
        scanner.close();

        // 初始化数组
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                map[i][j] = MAX;
            }
            minSpend[i] = MAX;
        }
        //先找到每个值的最短路
        for (int i = 1; i <= n - 1; i++) {
            for (int j = i + 1; j <= n; j++) {
                double x2 = (nodes[i].x - nodes[j].x) * (nodes[i].x - nodes[j].x);
                double y2 = (nodes[i].y - nodes[j].y) * (nodes[i].y - nodes[j].y);
                double h2 = (nodes[i].h - nodes[j].h) * (nodes[i].h - nodes[j].h);
                double temp = Math.sqrt(x2 + y2) + h2;
                map[i][j] = Math.min(map[i][j], temp);
                map[j][i] = map[i][j];
            }
        }
        // prime算法公式
        minSpend[1] = 0;    //  1 号村庄正好可以建立一个发电站
        for (int i = 1; i < n; i++) {
            int tempX = 0;
            for (int j = 1; j <= n; j++) {
                if (!vis[j] && (tempX == 0 || minSpend[j] < minSpend[tempX])) {
                    tempX = j;
                }
            }
            vis[tempX] = true;
            for (int j = 1; j <= n; j++) {
                if (!vis[j]) {
                    minSpend[j] = Math.min(minSpend[j], map[tempX][j]);
                }
            }
        }

        double res = 0.0;
        for (int i = 2; i <= n; i++) {
            res += minSpend[i];
        }
        System.out.printf("%.2f", res); // 保留两位小数
    }
}

